<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>代理商列表</title>

    <link rel="stylesheet" href="http://cdn.viptool.cn/lib/bootstrap/3.3.5/css/bootstrap.min.css">
    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}" rel="stylesheet">
    <!-- Morris -->
    <link href="http://cdn.viptool.cn/lib/morris.js/0.4.3/morris.css" rel="stylesheet">
    <link href="http://cdn.viptool.cn/lib/animate.css/2.1.1/animate.min.css" rel="stylesheet">
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}" rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css" th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="http://cdn.viptool.cn/lib/switchery/0.8.2/switchery.min.css" rel="stylesheet"/>
    <link href="http://cdn.viptool.cn/lib/bootstrap-daterangepicker/2.1.25/daterangepicker.min.css" rel="stylesheet">
    <link href="../../resource/lib/imageview/css/imageviewer.css" rel="stylesheet"/>

    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }

        .city-picker-selector select {

        }

        .daterangepicker {
            z-index: 999999999 !important;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <input type="hidden" name="status" th:value="*{status}"/>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="id">编号：</label>
                                <input type="text" class="form-control input-sm mb10" id="id" th:value="*{id}" name="id" placeholder="编号" style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="keyword">代理商：</label>
                                <input type="text" class="form-control input-sm mb10" id="keyword" th:value="*{keyword}" name="keyword" placeholder="手机号/姓名/昵称" style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="idCardNo">身份证：</label>
                                <input type="text" class="form-control input-sm mb10" id="idCardNo" th:value="*{idCardNo}" name="idCardNo" placeholder="身份证" style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="authCode">授权码：</label>
                                <input type="text" class="form-control input-sm mb10" id="authCode" th:value="*{authCode}" name="authCode" placeholder="授权码" style="width: 156px;"/>
                            </div>
                        </div>
                        <p style="height: 8px;"></p>
                        <div class="form-inline">
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="createTimePick">创建时间：</label>
                                <input type="text" class="form-control input-sm mb10 data-range-pick" id="createTimePick" start-element="#beginTime" end-element="#endTime" placeholder="开始时间-结束时间" style="width: 277px;"/>
                                <input type="hidden" th:value="*{beginTime}" id="beginTime" name="beginTime"/>
                                <input type="hidden" th:value="*{endTime}" id="endTime" name="endTime"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <button type="button" onclick="withdrawalHandler.search(1)"
                                        class="btn btn-primary btn-sm m-b-none searchBtn">筛选
                                </button>
                                <button type="button" onclick="withdrawalHandler.searchAll()" class="btn btn-primary btn-sm m-b-none">显示全部</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->

    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active" th:class="${condition.status==-1?'active':''}">
                            <a th:href="@{/withdrawal/list}" href="#tab-2">全部</a>
                        </li>
                        <li th:each="status:${statuses}" th:class="${condition.status==status.code?'active':''}">
                            <a th:href="@{/withdrawal/list(status=${status.code})}" th:text="${status.desc}">待审核</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body table-responsive">
                                <div class="form-inline" style="padding-bottom: 15px;text-align: right;">
                                    <button type="button" onclick="withdrawalHandler.exportModal()"
                                            class="btn btn-white btn-sm m-b-none">导出
                                    </button>
                                </div>
                                <table class="table table-bordered table-hover table-center">
                                    <thead>
                                    <tr>
                                        <th>编号</th>
                                        <th>账户</th>
                                        <th>提现方式</th>
                                        <th>提现金额</th>
                                        <th>状态</th>
                                        <th>收款信息</th>
                                        <th>申请时间</th>
                                        <th>用户留言</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                    <tr th:each="withdrawal:${withdrawals}">
                                        <td th:text="${withdrawal.drawalId}"></td>
                                        <td>
                                            <span th:text="|${withdrawal.userPO.realName}(${withdrawal.userPO.userLevelPO.levelName})|">王明(大区经理)</span>
                                            <br/>
                                            <span th:text="${withdrawal.userPO.username}">17678767675</span>
                                            <br/>
                                            <span th:text="${withdrawal.userPO.idcardNo}">33098988787676</span>
                                        </td>
                                        <td th:text="${withdrawal.channelType.desc}"></td>
                                        <td>
                                            提现金额：<span th:text="${withdrawal.totalMoney}">100.00</span>
                                            <br/>
                                            打款金额：<span th:text="${withdrawal.finalMoney}"></span>
                                            <br/>
                                            手续费：<span th:text="${withdrawal.feeMoney}"></span>
                                        </td>
                                        <td th:text="${withdrawal.status.desc}"></td>
                                        <td>
                                            <span th:text="${withdrawal.recAccount}">18787676676</span>
                                            <th:block th:if="${withdrawal.recBankName!=null}">
                                                <br/>
                                                <span th:text="${withdrawal.recBankName}">中国银行</span><span th:text="${withdrawal.recBankBranch}">西兴支行</span>
                                            </th:block>
                                        </td>
                                        <td th:text="${#temporals.format(withdrawal.createTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                                        <td th:text="${withdrawal.memo}"></td>
                                        <td>
                                            <th:block th:if="${withdrawal.status.code==0}">
                                                <button onclick="withdrawalHandler.agree('123')" th:onclick="|withdrawalHandler.agree('${withdrawal.drawalId}')|" type="button"
                                                        class="btn btn-primary btn-xs m-b-none">同意
                                                </button>
                                                <button onclick="withdrawalHandler.disagree('123')" th:onclick="|withdrawalHandler.disagree('${withdrawal.drawalId}')|" type="button"
                                                        class="btn btn-danger btn-xs m-b-none">拒绝
                                                </button>
                                            </th:block>

                                            <button th:if="${withdrawal.status.code==1}" onclick="withdrawalHandler.withdrawal('123')" th:onclick="|withdrawalHandler.withdrawal('${withdrawal.drawalId}')|" type="button"
                                                    class="btn btn-primary btn-xs m-b-none">打款
                                            </button>
                                            <button th:if="${withdrawal.status.code==2}" onclick="withdrawalHandler.withdrawalFailed('123')" th:onclick="|withdrawalHandler.withdrawalFailed('${withdrawal.drawalId}')|" type="button"
                                                    class="btn btn-danger btn-xs m-b-none">打款失败
                                            </button>
                                            <button onclick="withdrawalHandler.optLog('123')" th:onclick="|withdrawalHandler.optLog('${withdrawal.drawalId}')|" type="button"
                                                    class="btn btn-white btn-xs m-b-none">操作日志
                                            </button>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>

                                <p style="clear: both"></p>
                                <p class="color-danger">当前筛选条件下，总提现金额：￥<span th:text="${withdrawalSum.totalAmount}">20000</span>，总手续费：￥<span th:text="${withdrawalSum.totalFee}">2000</span>，打款总金额:<th:block th:text="${withdrawalSum.getFinalAmount()}"></th:block></p>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="check_modal" class="modal-content-tag">
    <form id="saveForm">
        <input type="hidden" id="check_drawal_id"/>
        <input type="hidden" id="check_status"/>
        <div class="form-horizontal" style="width: 479px;">
            <div class="form-group">
                <label class="col-sm-3 control-label">*拒绝理由：</label>
                <div class="col-sm-9">
                    <textarea placeholder="拒绝理由" name="check_remark" id="check_remark" class="form-control"
                              rows="5" style="height: 100px;width: 300px;"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>

<div id="export_modal" class="modal-content-tag">
    <form id="export_form">
        <div class="form-horizontal" style="width: 379px;">
            <div class="form-group form-inline">
                <label class="col-sm-3 control-label">*页数：</label>
                <div class="col-sm-9">
                    <input type="text" style="width: 50px;" value="1" name="export_firstPage" id="export_firstPage" class="form-control input-sm only-num" placeholder="起始页"/>
                    -
                    <input type="text" style="width: 50px;" value="1" name="export_lastPage" id="export_lastPage" class="form-control input-sm only-num" placeholder="终止页"/>

                    <p class="form-control-static color-notice">起始页-终止页</p>
                </div>
            </div>
        </div>
    </form>
</div>

<!--基础框架js-->
<script src="http://cdn.viptool.cn/lib/jquery/2.2.4/jquery.min.js"></script>
<script src="http://cdn.viptool.cn/lib/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316" th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316" th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="http://cdn.viptool.cn/lib/moment.js/2.19.2/moment.min.js"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>

<script src="../../resource/stagent/js/stagent.uri.constant.js" th:src="@{/resource/stagent/js/stagent.uri.constant.js}"></script>

<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/withdrawal/list}]]*/  "";
    const withdrawalApiBase = /*[[@{/withdrawal}]]*/  "/withdrawal";
    const withdrawalLogUri = /*[[@{/withdrawal/logs}]]*/  "withdrawal_opt_log.html";
    const exportUri = /*[[@{/withdrawal/exportExcel}]]*/  "withdrawal_opt_log.html";
</script>

<script>
    let checkModal = $("#check_modal").modal("备注", function () {
        let drawalId = $("#check_drawal_id").val();
        let status = $("#check_status").val();
        let remark = $("#check_remark").val();

        withdrawalHandler.check(drawalId, status, remark);
    });

    let exportModal = $("#export_modal").modal("导出", function () {
        withdrawalHandler.exportExcel();
    });

    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            withdrawalHandler.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                $(".searchBtn").trigger("click");
            }
        });
    });

    var withdrawalHandler = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        agree: function (drawalId) {
            hot.confirm("确定执行此操作？", function () {
                withdrawalHandler.check(drawalId, 1, null);
            });
        },
        disagree: function (drawalId) {
            checkModal.show(function () {
                $("#check_drawal_id").val(drawalId);
                $("#check_status").val(3);
            });
        },
        check: function (drawalId, status, remark) {
            hot.ajax(withdrawalApiBase + withdrawalUriConstant.check, {
                id: drawalId,
                rejectReason: remark,
                status: status
            }, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("操作成功，请尽快打款", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败--" + apiResult.resultMsg);
                }
            }, function () {
            }, "post", 300);
        },
        withdrawal: function (drawalId) {
            hot.confirm("确定执行此操作？", function () {
                hot.ajax(withdrawalApiBase + withdrawalUriConstant.withdrawal, {
                    id: drawalId,
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        })
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        },
        withdrawalFailed: function (drawalId) {
            hot.confirm("确定执行此操作？奖金将会退回", function () {
                hot.ajax(withdrawalApiBase + "/withdrawalFailed", {
                    id: drawalId,
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        })
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        },
        optLog: function (id) {
            hot.iframeModal(withdrawalLogUri + "?drawalId=" + id, '880px', '600px', "操作日志");
        },
        exportModal: function () {
            exportModal.show(function () {
                $("#export_firstPage").val(1);
                $("#export_lastPage").val(1);
            })
        },
        exportExcel: function () {
            let param = location.search;
            let firstPage = $("#export_firstPage").val();
            let lastPage = $("#export_lastPage").val();
            param += "&firstPage=" + firstPage + "&lastPage=" + lastPage;

            window.open(exportUri + param);
        }
    };
</script>
</body>
</html>
